package org.springblade.mach.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.mach.service.IDrawingWorkOrderService;
import org.springblade.mach.vo.DrawingWorkOrderQueryVO;
import org.springblade.mach.vo.DrawingWorkOrderVO;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

@RestController
@AllArgsConstructor
@RequestMapping("drawing/workorder")
@Api(value = "图纸工单关联表", tags = "图纸工单关联表接口")
public class DrawingWorkOrderController extends BladeController {

	private IDrawingWorkOrderService drawingWorkOrderService;

	@GetMapping("/findDrawingWorkOrderList")
	public R getDrawingWorkOrder(@RequestParam String workOrderQuery, Query pageQuery) {
		DrawingWorkOrderQueryVO searchObj = Func.readJson(workOrderQuery, DrawingWorkOrderQueryVO.class);
		IPage<DrawingWorkOrderVO> drawingWordOrderList =
			drawingWorkOrderService.getDrawingWordOrder(searchObj, pageQuery);
		return R.data(drawingWordOrderList);
	}

	@GetMapping("/downloadMaterielBom")
	public R downloadMaterielBom(String workOrderNo, String drawingNumberList, Integer billType,  HttpServletResponse response) {
		DrawingWorkOrderQueryVO workOrderQuery = new DrawingWorkOrderQueryVO();
		workOrderQuery.setBillType(billType);
		workOrderQuery.setDrawingNumberList(Func.toStrList(drawingNumberList));
		workOrderQuery.setWorkOrderNo(workOrderNo);
		drawingWorkOrderService.downloadMaterielBom(workOrderQuery, response);
		return R.status(true);
	}

}
